//用户登录
function Login(type) {
    var txtname = $("#txtname").val();
    var txtpwd = $("#txtpwd").val();
    if (txtname == "") {
        alert("Enter Your E-mail Address");
        return false;
    }
    if (txtpwd == "") {
        alert("Enter Your Password");
        return;
    }
    var ckeval = "0";
    if ($("input[name=ckeval]").attr("checked")) {
        ckeval = "1";
    }
    $.ajax({
        url: "/IAjax/Ajax.ashx",
        type: "POST",
        cache: false,
        dataType: "text",
        data: { action: "Login", username: escape(txtname), userpwd: escape(txtpwd), ckeval: ckeval },
        success: function (ReturnData) {
            if (ReturnData == "yes") {
                if (type == "1") {
                    location.reload();
                } else {
                    if (getUrlPara("rurl") == null) {
                        window.location.href = "/PersonalCenter.html";
                    }
                    else {
                        window.location.href = unescape(getUrlPara("rurl"));
                    }
                }
            }
            else {               
                alert(ReturnData);
            }
        }
    });
}


//发送验证码
function SendCode(obj) {

    var UserName = $("#UserName").val();
    $.ajax({
        url: "/IAjax/Ajax.ashx",
        type: "POST",
        cache: false,
        dataType: "xml",
        data: { action: "SendCode", UserName: escape(UserName) },
        success: function (ReturnData) {
            var state = $("response state", ReturnData).text();
            if (state == "yes") {
                alert("Verification Code has been sent by email,please check");
                settime(obj);
            }
            else {
                alert($("response errorinfo", ReturnData).text())
            }
        }
    });
}
var wait = 60;
function settime(obj) {
    if (wait == 0) {
        obj.removeAttribute("disabled");
        obj.value = "Get Code";
        wait = 60;
    } else {
        obj.setAttribute("disabled", true);
        obj.value = "Get Code(" + wait + ")";
        wait--;
        setTimeout(function () {
            settime(obj);
        }, 1000)
    }
}

//获取URL参数
function getUrlPara(paraName) {
    var sUrl = location.href;
    var sReg = "(?:\\?|&){1}" + paraName + "=([^&]*)"
    var re = new RegExp(sReg, "gi");
    if (re.exec(sUrl)) {
        return RegExp.$1.split('#')[0];
    }
    return null;
}

//密码修改
function ModifyPwd() {
    var txtOldPwd = $("#txtOldPwd").val();
    var txtNewPwd = $("#txtNewPwd").val();
    var txtNewRePwd = $("#txtNewRePwd").val();

    if (txtNewPwd != txtNewRePwd) {
        swal("修改失败", "确认新密码不一致，请重新输入!", "warning");
        return;
    }

    $.ajax({
        url: "/IAjax/Ajax.ashx",
        type: "POST",
        cache: false,
        dataType: "text",
        data: { action: "ModifyPwd", txtOldpwd: escape(txtOldPwd), txtNewPwd: escape(txtNewPwd) },
        success: function (ReturnData) {
            if (ReturnData == "yes") {
                swal("修改成功", "", "success");
                $("#txtOldPwd").val("");
                $("#txtNewPwd").val("");
                $("#txtNewRePwd").val("");
            }
            else {
                swal("修改失败", ReturnData, "warning");
            }
        }
    });
}
//提交地址
function SaveAddress() {
    $.ajax({
        url: "/IAjax/Ajax.ashx",
        type: "POST",
        cache: false,
        dataType: "text",
        data: $("#aspnetForm").serialize(),
        success: function (ReturnData) {
            if (ReturnData == "yes") {
                if (getUrlPara("rurl") == null) {

                    swal({ title: "保存成功", text: "", type: "success" }, function () { window.location.href = "/Member/AddressList.aspx"; });
                }
                else {
                    window.location.href = unescape(getUrlPara("rurl"));
                }
            }
            else {
                swal("保存失败", ReturnData, "warning");
            }
        }
    });
}

//提交地址
function SaveAddressShow() {
    $.ajax({
        url: "/IAjax/Ajax.ashx",
        type: "POST",
        cache: false,
        dataType: "text",
        data: $("#aspnetForm").serialize(),
        success: function (ReturnData) {
            if (ReturnData == "yes") {
                window.parent.webcommon.closeFb('配送地址保存成功', 1, 2000, true);
            }
            else {
                alert(ReturnData)
            }
        }
    });
}

